﻿using System;
using System.Web.Services;
using Dost.Khcn.Biz;
using Dost.Khcn.Model;
using Dost.Khcn.Web.Common;

namespace Dost.Khcn.Web.ChuyenGia
{
    public class List : System.Web.UI.Page
    {
        #region Properites

        private static ChuyenGiaBiz _chuyenGiaBiz;
        private static ChuyenGiaBiz ChuyenGiaManager
        {
            get { return _chuyenGiaBiz ?? (_chuyenGiaBiz = new ChuyenGiaBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (WebCommon.CurrrentEmployee == null)
            //{
            //    Response.Redirect("~/Logon.aspx");
            //    //return;
            //}

            //if (WebCommon.CurrrentEmployee.Role != UserRole.Admin)
            //{
            //    Response.Redirect("~/NoPermission.aspx");
            //}
        }

        #region Web methods

        [WebMethod(EnableSession = true)]
        public static object ChuyenGiaList(int jtStartIndex, int jtPageSize, string jtSorting, string hoTen, string tenDonVi, int hocHamId, int hocViId)
        {
            return ChuyenGiaManager.GetChuyenGiaViews(jtStartIndex, jtPageSize, jtSorting, hoTen, tenDonVi, hocHamId, hocViId);
        }

        [WebMethod(EnableSession = true)]
        public static object Delete(int Id)
        {
            return ChuyenGiaManager.DeleteChuyenGia(Id);
        }

        [WebMethod(EnableSession = true)]
        public static object Create(Data.EntityModel.ChuyenGia record)
        {
            try
            {
                var addedRecord = ChuyenGiaManager.CreateChuyenGia(record);
                return new { Result = "OK", Record = addedRecord };
            }
            catch (ApplicationException appEx)
            {
                return new { Result = "ERROR", Message = string.Format(WebCommon.GetGlobalString(appEx.Message), record.HoTen) };
            }
        }

        [WebMethod(EnableSession = true)]
        public static object Update(Data.EntityModel.ChuyenGia record)
        {
            try
            {
                ChuyenGiaManager.UpdateChuyenGia(record);
                return new { Result = "OK" };
            }
            catch (ApplicationException appEx)
            {
                return new { Result = "ERROR", Message = string.Format(WebCommon.GetGlobalString(appEx.Message), record.HoTen) };
            }
        }

        #endregion
    }
}